import React, { Component, ErrorInfo } from 'react';

import Erroring from '@/components/blank/error';

export default class ErrorBoundary extends Component {
  static getDerivedStateFromError() {
    return { hasError: true };
  }

  state = {
    hasError: false,
  };

  componentDidCatch(error: Error, info: ErrorInfo) {
    // 可以在这里添加日志
    console.warn('ErrorBoundary::something error:', error, info);
  }

  handleRetry() {
    location.reload();
  }

  render() {
    return this.state.hasError ? (
      <Erroring noborder onClick={this.handleRetry} height="80vh" />
    ) : (
      this.props.children
    );
  }
}
